package  
{
	import net.flashpunk.Entity;
	import net.flashpunk.utils.Input;
	import net.flashpunk.graphics.Image;
	import net.flashpunk.utils.Key;
	
	public class Girder extends Entity
	{
		[Embed(source = 'images/girder_small.gif')] private const SMALL:Class;
		[Embed(source = 'images/girder_medium.gif')] private const MEDIUM:Class;
		[Embed(source = 'images/girder_large.gif')] private const LARGE:Class;
		
		private var girder_small:Image = new Image(SMALL);
		private var girder_medium:Image = new Image(MEDIUM);
		private var girder_large:Image = new Image(LARGE);
		
		public var x_acceleration:int;
		public var x_velocity:int;
		
		public function Girder() 
		{
			type = "girder";
			graphic = new Image(LARGE);
			setHitbox(90, 2);
			y = 555;
			x = 250-halfWidth;
			x_acceleration = 0;
			x_velocity = 0;
			layer = 0;
		}
		
		override public function update():void {
			if (Input.check(Key.SPACE)) { }
			//calculating the girder's left/right velocity & acceleration
			if (Input.check(Key.RIGHT)) x_acceleration = x_acceleration + 2;
			if (Input.released(Key.RIGHT)) {
				x_acceleration = 0;
				x_velocity = 0;
			}
			if (Input.check(Key.LEFT)) x_acceleration = x_acceleration - 2;
			if (Input.released(Key.LEFT)) {
				x_acceleration = 0;
				x_velocity = 0;
			}
			if (x_acceleration > 4) x_acceleration = 4;
			if (x_acceleration < -4) x_acceleration = -4;
			if (x_velocity > 50) x_velocity = 50;
			if (x_velocity < -50) x_velocity = -50;
			x_velocity = x_velocity + x_acceleration;

			//Girder hits sides of screen
			x = x + x_velocity;
			if (x < 0) {
				x = 0;
				x_velocity = 0;
				x_acceleration = 0;
			}
			if (x > 500 - width) {
				x = 500 - width;
				x_velocity = 0;
				x_acceleration = 0;
			}
		}
		
	}

}